package com.example.spzs.Service;


import com.example.spzs.Task.getgoodsTask;
import com.example.spzs.mapper.goodsMapper;
import com.example.spzs.pojo.goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


import java.util.ArrayList;

@Component
public class getgoodsService {
    @Autowired
    private  goodsMapper goodsMapper;
    @Autowired
    getgoodsTask getgoodsTask;
    @Scheduled(fixedDelay = 30*1000)
    public boolean execute(){
        ArrayList<String> urlList = new ArrayList<>();
        urlList.add("https://j1.pupuapi.com/client/product/storeproduct/detail/deef1dd8-65ee-46bc-9e18-8cf1478a67e9/8bea2740-3de5-4db1-b406-de1e0e621049");
        urlList.add("https://j1.pupuapi.com/client/product/storeproduct/detail/deef1dd8-65ee-46bc-9e18-8cf1478a67e9/ec03188e-18b3-4abf-a726-5eed958612ad");
        urlList.add("https://j1.pupuapi.com/client/product/storeproduct/detail/deef1dd8-65ee-46bc-9e18-8cf1478a67e9/a333c5c6-823a-46ee-b332-d04bc1d3502c");
        urlList.add("https://j1.pupuapi.com/client/product/storeproduct/detail/deef1dd8-65ee-46bc-9e18-8cf1478a67e9/182a98b1-f47f-45b4-8085-cb8baf6d34bb");
        urlList.add("https://j1.pupuapi.com/client/product/storeproduct/detail/deef1dd8-65ee-46bc-9e18-8cf1478a67e9/f7737f6a-0f92-4bae-8382-3ecafbeb159d");
        urlList.add("https://j1.pupuapi.com/client/product/storeproduct/detail/deef1dd8-65ee-46bc-9e18-8cf1478a67e9/551183ea-252e-420b-9af8-d4ef27fc4400");
        urlList.add("https://j1.pupuapi.com/client/product/storeproduct/detail/deef1dd8-65ee-46bc-9e18-8cf1478a67e9/22fab5c8-e07f-4dce-aa2f-a146e6fae8e5");
        urlList.add("https://j1.pupuapi.com/client/product/storeproduct/detail/deef1dd8-65ee-46bc-9e18-8cf1478a67e9/a43399cc-3688-42c5-863a-a74c4cff1ad2");
        urlList.add("https://j1.pupuapi.com/client/product/storeproduct/detail/deef1dd8-65ee-46bc-9e18-8cf1478a67e9/a7294809-750c-473a-83d5-877f7a5ec9bc");
       urlList.add("https://j1.pupuapi.com/client/product/storeproduct/detail/deef1dd8-65ee-46bc-9e18-8cf1478a67e9/b9eb95da-a45d-480d-b813-ccfd7e01c046");
        goodsMapper.deleteAll();
        int i=0;
        for (String s : urlList) {

            goods goods = getgoodsTask.getgoods(s);

            if (goods.getSub_title()!=null&&!goods.getName().equals("")){
                i = goodsMapper.insertGoods(goods);
            }

        }
        if (i>0){return true;}
        return false;



    }
}
